<?php

namespace Admin;

use Admin\Model\Category;
use Admin\Model\Product;
use Admin\Model\ProductTable;
use Admin\Model\CategoryTable;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;

class Module {

	public function getAutoLoaderConfig() {
		$a = array(
			'Zend\Loader\ClassMapAutoloader' => array(
				__DIR__ . '/autoload_classmap.php',
			),
			'Zend\Loader\StandardAutoloader' => array(
				'namespaces' => array(
					__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
				),
			)
		);

		
		return $a;
	}

	public function getConfig() {
		return include __DIR__ . '/config/module.config.php';
	}

	public function getServiceConfig() {
		return array(
			'factories' => array(
				'Admin\Model\CategoryTable' => function($sm) {
					$tableGateway = $sm->get('CategoryTableGateway');
					$table = new CategoryTable($tableGateway);
					return $table;
				},
				'CategoryTableGateway' => function($sm) {
					$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
					$resultSetPrototype = new ResultSet();
					$resultSetPrototype->setArrayObjectPrototype(new Category());
					return new TableGateway('category', $dbAdapter, null, $resultSetPrototype);
				},
				'Admin\Model\ProductTable' => function($sm) {
					$tableGateway = $sm->get('ProductTableGateway');
					$table = new ProductTable($tableGateway);
					return $table;
				},
				'ProductTableGateway' => function($sm) {
					$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
					$resultSetPrototype = new ResultSet();
					$resultSetPrototype->setArrayObjectPrototype(new Product());
					return new TableGateway('product', $dbAdapter, null, $resultSetPrototype);
				},
				'Admin\Model\Product'	=> function($sm){
					$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
					$product = new Product();
					$product->setDbAdapter($dbAdapter);
					return $product;
				},
				'Admin\Validator\CategoryValid' => function($sm) {
					$validator = new Validator\CategoryValid();
					$validator->setServiceLocator($sm);
					return $validator;
				}
			)
		);
	}

}